import { IMAGE_FORMATS } from "~~/config";
type UseRequest = () => void

export const useRequest = (callback: (...params: any) => Promise<any>): UseRequest => {
  const loading = useState('request/loading', () => false)

  return () => {
    if(loading.value) {
      return 
    }

    loading.value = true

    callback().finally(() => loading.value = false)
  }
}

export const useNuxtImage = (src: string) => {
  const image = useImage();
  const imageComputed = computed(() => {
    return image(src, {
      formats: IMAGE_FORMATS,
    });
  });

  return imageComputed.value;
};

